<?php
namespace app\jobmanagement\controller;

use app\constdir\ApiConst;
use app\jobmanagement\service\TransferConfig as sTransferConfig;
class TransferConfig extends Base
{
    private $sTransferConfig;
    public function __construct(){
        parent::__construct();
        $this->sTransferConfig = new sTransferConfig();
    }


    /**
     * @introduction:修改转账相关配置项数据
     * @return \think\Collection|\think\model\Collection
     * @author:cxh
     * @date: 2020/7/2 17:57
     */
    public function saveTransferConfig(){

        $param = [
            'id' => (int)input('id'),
            'days_between_withdrawals' => (int)input('days_between_withdrawals'),
            'guaranteed_cash_withdrawal' => (float)input('guaranteed_cash_withdrawal'),
            'maximum_single_cash_withdrawal' => (float)input('maximum_single_cash_withdrawal')
        ];

        if (empty($param['id'])) {
            return $this->apiError(ApiConst::TRANSFER_CONFIG_ID_NO_ERROR_MSG,ApiConst::TRANSFER_CONFIG_ID_NO_ERROR_CODE);
        }
        if ($param['days_between_withdrawals'] < 0) {
            return $this->apiError(ApiConst::TRANSFER_CONFIG_NUM_ERROR_MSG,ApiConst::TRANSFER_CONFIG_NUM_ERROR_CODE);
        }
        if ($param['guaranteed_cash_withdrawal'] < 0) {
            return $this->apiError(ApiConst::TRANSFER_CONFIG_FLOAT_ERROR_MSG,ApiConst::TRANSFER_CONFIG_FLOAT_ERROR_CODE);
        }
        if (!is_float($param['maximum_single_cash_withdrawal'])) {
            return $this->apiError(ApiConst::TRANSFER_CONFIG_FLOAT_ERROR_MSG,ApiConst::TRANSFER_CONFIG_FLOAT_ERROR_CODE);
        }


        $info =  $this->sTransferConfig->saveTransferConfig($param);

        return $this->apiSuccessError($info);

    }


    /**
     * @introduction:相关数据输出
     * @return \think\Collection|\think\model\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @author:cxh
     * @date: 2020/7/2 17:57
     */
    public function viewTransferConfig(){

        $info =  $this->sTransferConfig->viewTransferConfig();

        return $this->apiSuccessError($info);
    }



}
